package com.liwei.blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.liwei.blog.dao.BlogDao;
import com.liwei.blog.dao.UserDao;
import com.liwei.blog.pojo.Blog;
import com.liwei.blog.pojo.User;
import com.liwei.blog.service.EsBlogService;
import com.liwei.blog.vo.TagVO;

/** 
* @author 作者 liwei: 
* @version 创建时间：2018年12月9日 下午7:16:38 
* 类说明 
*/
@Service
public class EsBlogServiceImpl  implements EsBlogService{

	@Autowired
	BlogDao blogDao;
	
	@Autowired
	UserDao userDao;
	@Override
	public void removeEsBlog(String id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Blog updateEsBlog(Blog esBlog) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Blog getEsBlogByBlogId(Long blogId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<Blog> listNewestEsBlogs(String title,Pageable pageable) {
		// 模糊查询
		// 模糊查询
		title = "%" + title + "%";
		Page<Blog> blogs = blogDao.findByTitleLikeOrderByCreateTimeDesc(title,pageable);
		return blogs;
	}

	@Override
	public Page<Blog> listHotestEsBlogs(String title,Pageable pageable) {
		// 模糊查询
		title = "%" + title + "%";
		Page<Blog> blogs = blogDao.findByTitleLike(title, pageable);
		return blogs;
	}

	@Override
	public Page<Blog> listEsBlogs(Pageable pageable) {
		// TODO Auto-generated method stub
		return blogDao.findAll(pageable);
	}

	@Override
	public List<Blog> listTop5NewestEsBlogs() {
		Page<Blog> blogs = this.listNewestEsBlogs("",new PageRequest(0, 5));
		return blogs.getContent();
	}

	@Override
	public List<Blog> listTop5HotestEsBlogs() {
		Sort sort = new Sort(Direction.DESC,"reading","commentSize","voteSize"); 
		Pageable pageable = new PageRequest(0, 5, sort);
		Page<Blog> blogs = this.listHotestEsBlogs("",pageable);
		return blogs.getContent();
	}

	@Override
	public List<TagVO> listTop30Tags() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> listTop12Users() {
		Page<User> users =userDao.findAll(new PageRequest(0, 12));
		List<User> content = users.getContent();
		return content;
	}

}
